#include "rb_helper.h"

#if 0

float3 g_dirs[] = 
{   
    float3(1,0,0), float3(-1,0,0),
    float3(0,1,0), float3(0,-1,0),
    float3(0,0,1), float3(0,0,-1)
};

float3 g_ups[] = 
{   
    float3(0,1,0), float3(0,1,0),
    float3(0,0,-1), float3(0,0,1),
    float3(0,1,0), float3(0,1,0)
};


namespace rb_helper
{

UINT64 render_cube(float3 pos, RBCamera* camera, RBRenderTargetGroup* target, ID3D11Query* query, uint32 mask)
{
    UINT64 pixel_passed = 0;
    camera->WorldXForm().Translate = pos;
    for (uint32 ui=0; ui < 6; ++ui)
    {
        if (((1<<ui) & mask) == 0) continue;

        camera->LookAt(g_dirs[ui], g_ups[ui]);
        // Go left handed because we handle with a reflection
        {
            float* col_x = camera->WorldXForm().Rotate.GetCol(RBCamera::CD_RIGHT);
            col_x[0] = -col_x[0];
            col_x[1] = -col_x[1];
            col_x[2] = -col_x[2];
        }

        RBGeometryArray geoms;
        {
            PROFILE_BLOCK(RBApplication_Visibility);
            rb_render_pass::collect_geometries(&geoms, camera, RBApplication::GetSingleton()->get_scene());
        }

        {
            PROFILE_BLOCK(RBApplication_Render);
            rb_render_pass::open_render_target_group(RBRenderer::GetSingleton(), target, RBRenderer::CF_ALL, RBColorA(0,1,1,1));
            RBD3D11Renderer::GetSingleton()->GetDeviceContext()->Begin(query);
            rb_render_pass::render_geometries(RBRenderer::GetSingleton(), geoms, camera);
            RBD3D11Renderer::GetSingleton()->GetDeviceContext()->End(query);
        }

        RBD3D11Renderer::GetSingleton()->Flush();

        UINT64 queryData; // This data type is different depending on the query type
        while( S_OK != RBD3D11Renderer::GetSingleton()->GetDeviceContext()->GetData(query, &queryData, sizeof(UINT64), 0) )
        {
            ::Sleep(1);
        }

        pixel_passed += queryData;
    }

    return pixel_passed;

}

}

#endif